package com.comall.dc.banktest.infrastructure.dao.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.comall.dc.banktest.domain.model.Account;
import com.comall.dc.banktest.infrastructure.dao.service.AccountDAO;
import com.comall.dc.banktest.infrastructure.entity.AccountPO;
import com.comall.dc.banktest.infrastructure.dao.mapper.IAccountMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 * 用户账户 服务实现类
 * </p>
 *
 * @author GodMeowIceSun
 * @since 2021-11-02
 */
@Service
public class AccountDAOImpl extends ServiceImpl<IAccountMapper, AccountPO> implements AccountDAO {

    @Override
    public List<AccountPO> listByTimeRangeAndLikeIdAndLikeIdCardAndLikeUserPhone(
            LocalDateTime beginTime, LocalDateTime endTime, String likeId, String likeIdCard, String likeUserPhone) {
        return this.list(Wrappers.<AccountPO>lambdaQuery()
                .between(AccountPO::getCreateTime, beginTime, endTime)
                .like(AccountPO::getId, likeId)
                .like(AccountPO::getIdCard, likeIdCard)
                .like(AccountPO::getUserPhone, likeUserPhone));
    }

    @Override
    public boolean isIdCardExist(String idCard) {
        Long count = this.count(Wrappers.<AccountPO>lambdaQuery().eq(AccountPO::getIdCard, idCard));
        return count.compareTo(0L) > 0;
    }
}
